<template>
    <div class="header">
        <div class="header-abs" v-show="showAbs">
            <div class="header-abs-back iconfont" @click="backToHome"></div>
        </div>
        <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
            <div class="header-fixed-back iconfont" @click="backToHome"></div>
            景点详情
        </div>
    </div>
</template>

<script>
export default {
    name: 'DetailHeader',
    data() {
        return {
            showAbs: true,
            opacityStyle: {
                opacity: 0
            }
        }
    },
    methods: {
        backToHome() {
            this.$router.push({
                path: '/'
            })
        },
        handleScroll() {
            const top = document.documentElement.scrollTop
            let opacity = top / 135
            opacity = opacity > 1 ? 1 : opacity
            this.opacityStyle = { opacity }
            this.showAbs = top < 35
        }
    },
    activated() {
        window.addEventListener('scroll', this.handleScroll)
    },
    deactivated() {
        window.removeEventListener('scroll', this.handleScroll)
    }
}
</script>

<style lang="scss" scoped>
@import '~styles/varibles.scss';
.header{
    .header-abs{
        position: absolute;
        left: 0.2rem;
        top: 0.2rem;
        width: 0.5rem;
        height: 0.5rem;
        line-height: 0.5rem;
        border-radius: 50%;
        background: rgba($color: #000000, $alpha: 0.7);
        .header-abs-back{
            &:after {
                content: "\e658";
                font-size: 0.5rem;
                text-align: center;
                color: #ccc;
            }
        }
    }
    .header-fixed{
        z-index: 2;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: $headerHeight;
        line-height: $headerHeight;
        background: $bgColor;
        text-align: center;
        color: #fff;
        .header-fixed-back{
            &:before{
                position: absolute;
                left: 0;
                top: 0;
                content: "\e658";
                font-size: 0.4rem;
                color: #fff;
            }
        }
    }
}
</style>
